import MySQLdb
from concurrent.futures import ThreadPoolExecutor
from threading import Thread


class ConnectMysql(object):

    def __init__(self):
        self.conn = MySQLdb.Connect(host='47.111.246.162', port=3306, user='root', passwd='root', db='article_spider', charset='utf8')
        print(self.conn)
        self.cursor = self.conn.cursor()

    def transaction(self):
        self.cursor.execute("set @m = 0;")
        self.cursor.execute('SELECT age into @m from city where id = 20;')
        self.cursor.execute('UPDATE city set age = @m+1 where id =20;')
        self.conn.commit()

    def thread(self):
        # tpool = ThreadPoolExecutor(max_workers=5)
        #for item in range(10):
         #   tpool.submit(self.transaction)
        #tpool.shutdown()
        lst = []
        for item in range(2):
            t = Thread(target=self.transaction)
            t.start()
            lst.append(t)
        for i in lst:
            i.join()
        print('xiong')
        # self.cursor.close()
        #self.conn.close()
try:
    ConnectMysql().thread()
except Exception as a:
    print(a)